﻿Imports System.Xml.Serialization
Imports System.IO

Public Class ObjectSerializer

    Public Shared Sub WriteObjectAsXML(ByVal anObjects As Objects, ByVal aXMLFilePath As String)
        Dim serializer As New XmlSerializer(anObjects.GetType)
        Dim tw As TextWriter = New StreamWriter(aXMLFilePath)
        serializer.Serialize(tw, anObjects)
        tw.Close()
    End Sub

    Public Shared Function ReadObjectFromXML(ByVal aXMLFilePath As String) As Objects
        If (Not IO.File.Exists(aXMLFilePath)) Then Return Nothing
        Dim tr As TextReader = New StreamReader(aXMLFilePath, FileMode.Open)
        Dim serializer As New XmlSerializer(GetType(Objects))
        Dim myObjects As Objects = serializer.Deserialize(tr)
        Return myObjects
    End Function

End Class
